package cn.iocoder.yudao.adminserver.franky.strategy;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: franky
 * @CreateDate: 2021/6/24 10:01 下午
 * @Version: 1.0
 */
public interface DiscountStrategy20210624 {

    void calDiscount(Order20210624 order20210624);

}

class NorDiscount implements DiscountStrategy20210624{
    @Override
    public void calDiscount(Order20210624 order20210624) {

    }
}

class GrouponDiscount implements DiscountStrategy20210624 {
    @Override
    public void calDiscount(Order20210624 order20210624) {

    }
}

class PromotionDiscount implements DiscountStrategy20210624 {
    @Override
    public void calDiscount(Order20210624 order20210624) {

    }
}

@Data
class Order20210624 {
    OrderType20210624 orderType20210624;

}

enum OrderType20210624 {
    normal,
    promotion,
    groupon;
}

class DiscountFactory20210624 {
    public static final Map<OrderType20210624, DiscountStrategy20210624> discountMap = new HashMap<>();

    static {
        discountMap.put(OrderType20210624.normal, new NorDiscount());
        discountMap.put(OrderType20210624.groupon, new GrouponDiscount());
        discountMap.put(OrderType20210624.promotion, new PromotionDiscount());
    }

    public static DiscountStrategy20210624 getDiscount(OrderType20210624 orderType20210624) {
        return discountMap.get(orderType20210624);
    }
}

class OrderService20210624 {
    public void discount(Order20210624 o) {
        OrderType20210624 ot = o.getOrderType20210624();
        DiscountFactory20210624.getDiscount(ot).calDiscount(o);
    }
}